package com.vf.admin.client.controller.pay.sandpay;


import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.vf.admin.client.common.ClientBaseController;
import com.vf.admin.client.common.ClientConstants;
import com.vf.admin.client.controller.pay.sandpay.util.CertUtil;
import com.vf.admin.client.controller.pay.sandpay.util.CryptoUtil;
import com.vf.admin.client.dao.VipOrderDao;
import com.vf.admin.client.result.PayInfoResult;
import com.vf.admin.client.service.*;
import com.vf.admin.common.entity.Result;
import com.vf.admin.fiwork.controller.AppDailyTasController;
import com.vf.admin.miaodong.entity.*;
import com.vf.admin.client.controller.pay.sandpay.alipay.SandAliPayService;
import com.vf.admin.client.controller.pay.sandpay.weixin.SandWeiXinPayService;
import com.vf.admin.miaodong.service.AfterUserService;
import com.vf.admin.utils.Md5Util1;
import org.apache.commons.codec.binary.Base64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.HashMap;

import static com.vf.admin.common.Constants.*;


/**
 * <p>Title : 杉德支付</p>
 * <p>Description : </p>
 * <p>DevelopTools : IDEA</p>
 * <p>DevelopSystem : Windows10</p>
 *
 * @Author : NemoMeng
 * @Date 2023/7/1 17:35
 */
@Controller
@CrossOrigin
@RequestMapping(value = "/api/sandPay")
public class ApiSandPayController extends ClientBaseController {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private SandWeiXinPayService sandWeiXinPayService;
    @Autowired
    private SandAliPayService sandAliPayService;

    //appSetup设置
    @Autowired
    private AppSetupService appSetupService;
    //用户信息
    @Autowired
    private AppUserService appUserService;
    //充值金额信息
    @Autowired
    private AppCzMoneyService appCzMoneyService;
    //钱包订单
    @Autowired
    private AppOrderService appOrderService;


    @Autowired
    private AppMingXiZuanShiService appMingXiZuanShiService;
    @Autowired
    private AppMingxiChongzhiService appMingxiChongzhiService;
    @Autowired
    private AppDailyTasController appDailyTasController;
    @Autowired
    private AppPrivilegeService appPrivilegeService;
    @Autowired
    private AppInvitationRecordService appInvitationRecordService;

    @Autowired
    private VipOrderDao vipOrderDao;

    //会员充值金额信息
    @Autowired
    private VipPackageService vipPackageService;

    //vip订单
    @Autowired
    private VipOrderService vipOrderService;

    @Autowired
    private PhpUserService phpUserService;

    @Autowired
    AfterUserService afterUserService;

    /**
     * h5杉德微信支付
     */
    @RequestMapping(value = "/weiXinRechargeH5", method = RequestMethod.POST)
    @ResponseBody
    public Result weiXinRechargeH5(HttpServletRequest request, Integer type, Integer projectId, String mobileSpec) {

        if (type == 1) {
            //提示
            AppSetup setup = appSetupService.get();
            if (setup.getOpenRecharge() == 0) {
                return this.errorJSON(setup.getRechargeTip());
            }
            //获取用户信息
            AppUser user = appUserService.get(getUserId());
            AppCzMoney appCzMoney = appCzMoneyService.get(projectId);
            //杉德支付业务
            PayInfoResult payInfoResult = sandWeiXinPayService.diamondRechargeH5(request, user, appCzMoney, mobileSpec);

            return this.sucessJSON(payInfoResult);
        }
        if (type == 2) {
            //提示
            AppSetup setup = appSetupService.get();
            if (setup.getOpenBuyVip() == 0) {
                return this.errorJSON(setup.getBuyVipTip());
            }
            //获取用户信息
            AppUser user = appUserService.get(getUserId());
            VipPackage vipPackage = vipPackageService.info(projectId);
            //杉德支付业务
            PayInfoResult payInfoResult = sandWeiXinPayService.openVipRechargeH5(request, user, vipPackage, mobileSpec);

            return this.sucessJSON(payInfoResult);

        }
        return this.errorJSON("请求参数不正确!");
    }

    /**
     * h5支付宝支付
     */

    @RequestMapping(value = "/aliPayRechargeH5", method = RequestMethod.POST)
    @ResponseBody
    public Result aliPayRechargeH5(HttpServletRequest request, Integer type, Integer projectId, String mobileSpec) {

        if (type == 1) {
            //提示
            AppSetup setup = appSetupService.get();
            if (setup.getOpenRecharge() == 0) {
                return this.errorJSON(setup.getRechargeTip());
            }
            //获取用户信息
            AppUser user = appUserService.get(getUserId());
            AppCzMoney appCzMoney = appCzMoneyService.get(projectId);
            //杉德支付业务
            PayInfoResult payInfoResult = sandAliPayService.diamondRechargeH5(request, user, appCzMoney, mobileSpec);

            return this.sucessJSON(payInfoResult);
        }
        if (type == 2) {
            //提示
            AppSetup setup = appSetupService.get();
            if (setup.getOpenBuyVip() == 0) {
                return this.errorJSON(setup.getBuyVipTip());
            }
            //获取用户信息
            AppUser user = appUserService.get(getUserId());
            VipPackage vipPackage = vipPackageService.info(projectId);
            //杉德支付业务
            PayInfoResult payInfoResult = sandAliPayService.openVipRechargeH5(request, user, vipPackage, mobileSpec);

            return this.sucessJSON(payInfoResult);
        }
        return this.errorJSON("请求参数不正确!");
    }


//    //回调
//    @RequestMapping(value = "/wxCallBack", method = RequestMethod.POST)
//    @ResponseBody
//    public String callBack(HttpServletRequest req, HttpServletResponse resp) {
//
//        String data = req.getParameter("data");
//        String sign = req.getParameter("sign");
//        logger.info("接收到前台通知数据：" + data);
//        logger.info("接收到前台通知签名：" + sign);
//        // 验证签名
//        boolean valid;
//        try {
//            valid = CryptoUtil.verifyDigitalSign(data.getBytes("utf-8"), Base64.decodeBase64(sign),
//                    CertUtil.getPublicKey(), "SHA1WithRSA");
//            if (!valid) {
//                logger.error("verify sign fail.");
//                logger.error("签名字符串(data)为：" + data);
//                logger.error("签名值(sign)为：" + sign);
//            } else {
//                logger.info("verify sign success");
//                JSONObject dataJson = JSONObject.parseObject(data);
//                if (dataJson != null) {
//                    if (dataJson.getJSONObject("head").getString("respCode").equals("000000")) {
//                        String url = "jsp/payResult.jsp";
//                        req.getRequestDispatcher(url).forward(req, resp);
//                        if (dataJson.getJSONObject("body").getString("orderStatus").equals("1")) {
//
//                            String orderNo = dataJson.getJSONObject("body").getString("tradeNo");
//                            System.out.println("回调订单号:" + orderNo);
//                            if (ObjectUtil.isNotEmpty(orderNo)) {
//                                //钱包                                                                       4              1
//                                AppOrder order = appOrderService.getByOrdernum(orderNo, dingdan_zhiFuLeiXing_shande_wx, dingdan_status_dfk);
//                                if (ObjectUtil.isNotEmpty(order)) {
//
//                                    AppUser user = appUserService.get(order.getUserid());
//                                    //存在则更改预订单支付状态
//                                    appOrderService.updateStastusYzf(order.getOrdernum(), dingdan_zhiFuLeiXing_shande_wx);
//                                    BigDecimal getDiamond = order.getNum();
//                                    //添加用户钻石金额
//                                    appUserService.updateZuanShi(user.getId(), getDiamond);
//                                    //增加用户累积充值金额
//                                    appUserService.updateLeijiChongzhi(user.getId(), order.getMoney());
//                                    //添加钻石明细
//                                    appMingXiZuanShiService.addMingxi(user.getId(), getDiamond, 1, "钻石充值");
//                                    //添加充值明细
//                                    appMingxiChongzhiService.addMingxi(user.getId(), getDiamond, 1, order.getMoney(), order.getOrdernum(), order.getMobileSpec());
//                                    //完成充值任务
//                                    appDailyTasController.getAwardOnce(order.getUserid(), ClientConstants.TaskOnce.RECHARGE_FIRST);
//                                    //如果有上级发放用户充值提成
//                                    addAward(order);
//                                    //升级贵族
//                                    appPrivilegeService.isUpLevel(user);
//                                }
//                                //vip充值
//                                VipOrder vipOrder = vipOrderService.getByOrderNum(orderNo, dingdan_zhiFuLeiXing_shande_zfb, 0);
//                                if (ObjectUtil.isNotEmpty(vipOrder)) {
//
//                                    if (vipOrder.getVipPackageId().equals(1000)) {
//                                        VipOrder vipOrder1 = vipOrderService.infoByOrderNo(orderNo);
//                                        vipOrder1.setStatus(1);
//                                        vipOrderDao.update(vipOrder1);
//                                        //更改状态
//                                        appUserService.upstateWindowTicket(vipOrder.getUserId());
//
//                                    } else {
//                                        //更改订单状态
//                                        vipOrderService.successCall(orderNo);
//                                    }
//
//                                }
//                            }
//                        }
//                    }
//                } else {
//                    logger.error("通知数据异常！！！");
//                }
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return null;
//    }

    //回调
    @RequestMapping(value = "/wxCallBack", method = RequestMethod.POST)
    @ResponseBody
    public String callBack(HttpServletRequest req, HttpServletResponse resp) {

        String data = req.getParameter("data");
        String sign = req.getParameter("sign");
        logger.info("接收到前台通知数据：" + data);
        logger.info("接收到前台通知签名：" + sign);
        // 验证签名
        boolean valid;
        try {
            valid = CryptoUtil.verifyDigitalSign(data.getBytes("utf-8"), Base64.decodeBase64(sign),
                    CertUtil.getPublicKey(), "SHA1WithRSA");
            if (!valid) {
                logger.error("verify sign fail.");
                logger.error("签名字符串(data)为：" + data);
                logger.error("签名值(sign)为：" + sign);
            } else {
                logger.info("verify sign success");
                JSONObject dataJson = JSONObject.parseObject(data);
                if (dataJson != null) {
                    if (dataJson.getJSONObject("head").getString("respCode").equals("000000")) {
                        String url = "jsp/payResult.jsp";
                        req.getRequestDispatcher(url).forward(req, resp);
                        if (dataJson.getJSONObject("body").getString("orderStatus").equals("1")) {

                            String orderNo = dataJson.getJSONObject("body").getString("tradeNo");
                            System.out.println("回调订单号:" + orderNo);
                            if (ObjectUtil.isNotEmpty(orderNo)) {
                                //钱包                                                                       4              1
                                AppOrder order = appOrderService.getByOrdernum(orderNo, dingdan_zhiFuLeiXing_shande_wx, dingdan_status_dfk);
                                if (ObjectUtil.isNotEmpty(order)) {

                                    AppUser user = appUserService.get(order.getUserid());
                                    //存在则更改预订单支付状态
                                    appOrderService.updateStastusYzf(order.getOrdernum(), dingdan_zhiFuLeiXing_shande_wx);
                                    BigDecimal getDiamond = order.getNum();
                                    //添加用户钻石金额
                                    appUserService.updateZuanShi(user.getId(), getDiamond);
                                    //增加用户累积充值金额
                                    appUserService.updateLeijiChongzhi(user.getId(), order.getMoney());
                                    //添加钻石明细
                                    appMingXiZuanShiService.addMingxi(user.getId(), getDiamond, 1, "钻石充值");
                                    //添加充值明细
                                    appMingxiChongzhiService.addMingxi(user.getId(), getDiamond, 1, order.getMoney(), order.getOrdernum(), order.getMobileSpec());
                                    //完成充值任务
                                    appDailyTasController.getAwardOnce(order.getUserid(), ClientConstants.TaskOnce.RECHARGE_FIRST);
                                    //如果有上级发放用户充值提成
                                    addAward(order);
                                    //升级贵族
                                    appPrivilegeService.isUpLevel(user);
                                }
                                //vip充值
                                VipOrder vipOrder = vipOrderService.getByOrderNum(orderNo, dingdan_zhiFuLeiXing_shande_zfb, 0);
                                if (ObjectUtil.isNotEmpty(vipOrder)) {
                                    Integer vipPackageId = vipOrder.getVipPackageId();
                                    //门票
                                    if (vipPackageId.equals(1000)) {

                                        VipOrder vipOrder1 = vipOrderService.infoByOrderNo(orderNo);
                                        vipOrder1.setStatus(1);
                                        vipOrderDao.update(vipOrder1);
                                        //更改状态
                                        appUserService.upstateWindowTicket(vipOrder.getUserId());
                                        afterUserService.upWhiteStatus(vipOrder.getUserId(), 2);
                                    }
                                    //会员
                                    if (vipPackageId.equals(101) || vipPackageId.equals(102) || vipPackageId.equals(103)) {

                                        //更改订单状态
                                        vipOrderService.successCall(orderNo);
                                        afterUserService.upWhiteStatus(vipOrder.getUserId(), 2);
                                    }


                                    //php

                                    //4 门票
                                    if (vipPackageId.equals(4)) {

                                        VipOrder vipOrder1 = vipOrderService.infoByOrderNo(orderNo);
                                        vipOrder1.setStatus(1);
                                        vipOrderDao.update(vipOrder1);
                                        //生成门票数据
                                        phpUserService.callBackWindowTick(vipOrder1.getUserId());

                                        //回调php


                                        //可以单独传入http参数，这样参数会自动做URL编码，拼接在URL中

                                        Integer types = 1;

                                        String param = "key:26e97719fb48687d42681b0ead73c418,uid:" + vipOrder1.getUserId() + ",money:" + vipOrder1.getPrice() + ",type:" + types;

                                        String ss = Md5Util1.md5Hex(param);

                                        HashMap<String, Object> paramMap = new HashMap<>();

                                        paramMap.put("singer", ss);
                                        paramMap.put("uid", vipOrder1.getUserId());
                                        paramMap.put("money", vipOrder1.getPrice());
                                        paramMap.put("type", types);
                                        String result = HttpUtil.get("https://poposeapi.ptszyxx.com/apa/Shujuhaonv/play", paramMap);

                                        System.out.println(result);


                                    }
                                    //会员  1三天  2一个月  3六个月  7 12个月
                                    if (vipPackageId.equals(1) || vipPackageId.equals(2) || vipPackageId.equals(3) || vipPackageId.equals(7)) {

                                        VipOrder vipOrder1 = vipOrderService.infoByOrderNo(orderNo);
                                        vipOrder1.setStatus(1);
                                        vipOrderDao.update(vipOrder1);
                                        //生成会员数据
                                        phpUserService.callBackVip(vipOrder1.getUserId(), vipPackageId);

                                        Integer types = null;

                                        if (vipPackageId.equals(1)){
                                            types = 2;
                                        }
                                        if (vipPackageId.equals(2)){
                                            types = 3;
                                        }
                                        if (vipPackageId.equals(3)){
                                            types = 4;
                                        }
                                        if (vipPackageId.equals(7)){
                                            types = 5;
                                        }
                                        String param = "key:26e97719fb48687d42681b0ead73c418,uid:" + vipOrder1.getUserId() + ",money:" + vipOrder1.getPrice() + ",type:" + types;

                                        String ss = Md5Util1.md5Hex(param);

                                        HashMap<String, Object> paramMap = new HashMap<>();

                                        paramMap.put("singer", ss);
                                        paramMap.put("uid", vipOrder1.getUserId());
                                        paramMap.put("money", vipOrder1.getPrice());
                                        paramMap.put("type", types);
                                        String result = HttpUtil.get("https://poposeapi.ptszyxx.com/apa/Shujuhaonv/play", paramMap);

                                        System.out.println(result);

                                    }
                                }
                            }
                        }
                    }
                } else {
                    logger.error("通知数据异常！！！");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    //回调
    @RequestMapping(value = "/zfbCallBack", method = RequestMethod.POST)
    @ResponseBody
    public String zfbCallBack(HttpServletRequest req, HttpServletResponse resp) throws Exception {

        String data = req.getParameter("data");
        String sign = req.getParameter("sign");
        logger.info("接收到前台通知数据：" + data);
        logger.info("接收到前台通知签名：" + sign);
        // 验证签名
        boolean valid;
        try {
            valid = CryptoUtil.verifyDigitalSign(data.getBytes("utf-8"), Base64.decodeBase64(sign),
                    CertUtil.getPublicKey(), "SHA1WithRSA");
            if (!valid) {
                logger.error("verify sign fail.");
                logger.error("签名字符串(data)为：" + data);
                logger.error("签名值(sign)为：" + sign);


            } else {
                logger.info("verify sign success");
                JSONObject dataJson = JSONObject.parseObject(data);
                if (dataJson != null) {
                    if (dataJson.getJSONObject("head").getString("respCode").equals("000000")) {
                        String url = "jsp/payResult.jsp";
                        req.getRequestDispatcher(url).forward(req, resp);
                        if (dataJson.getJSONObject("body").getString("orderStatus").equals("1")) {

                            String orderNo = dataJson.getJSONObject("body").getString("tradeNo");
                            if (ObjectUtil.isNotEmpty(orderNo)) {

                                //钱包                                                             4                               1
                                AppOrder order = appOrderService.getByOrdernum(orderNo, dingdan_zhiFuLeiXing_shande_zfb, dingdan_status_dfk);
                                if (ObjectUtil.isNotEmpty(order)) {

                                    AppUser user = appUserService.get(order.getUserid());
                                    //存在则更改预订单支付状态
                                    appOrderService.updateStastusYzf(order.getOrdernum(), dingdan_zhiFuLeiXing_shande_zfb);
                                    BigDecimal getDiamond = order.getNum();
                                    //添加用户钻石金额
                                    appUserService.updateZuanShi(user.getId(), getDiamond);
                                    //增加用户累积充值金额
                                    appUserService.updateLeijiChongzhi(user.getId(), order.getMoney());
                                    //添加钻石明细
                                    appMingXiZuanShiService.addMingxi(user.getId(), getDiamond, 1, "钻石充值");
                                    //添加充值明细
                                    appMingxiChongzhiService.addMingxi(user.getId(), getDiamond, 1, order.getMoney(), order.getOrdernum(), order.getMobileSpec());
                                    //完成充值任务
                                    appDailyTasController.getAwardOnce(order.getUserid(), ClientConstants.TaskOnce.RECHARGE_FIRST);
                                    //如果有上级发放用户充值提成
                                    addAward(order);
                                    //升级贵族
                                    appPrivilegeService.isUpLevel(user);
                                }

                                //vip充值
                                VipOrder vipOrder = vipOrderService.getByOrderNum(orderNo, dingdan_zhiFuLeiXing_shande_zfb, 0);
                                if (ObjectUtil.isNotEmpty(vipOrder)) {
                                    Integer vipPackageId = vipOrder.getVipPackageId();
                                    //门票
                                    if (vipPackageId.equals(1000)) {

                                        VipOrder vipOrder1 = vipOrderService.infoByOrderNo(orderNo);
                                        vipOrder1.setStatus(1);
                                        vipOrderDao.update(vipOrder1);
                                        //更改状态
                                        appUserService.upstateWindowTicket(vipOrder.getUserId());
                                        afterUserService.upWhiteStatus(vipOrder.getUserId(), 2);
                                    }
                                    //会员
                                    if (vipPackageId.equals(101) || vipPackageId.equals(102) || vipPackageId.equals(103)) {

                                        //更改订单状态
                                        vipOrderService.successCall(orderNo);
                                        afterUserService.upWhiteStatus(vipOrder.getUserId(), 2);
                                    }


                                    //php

                                    //4 门票
                                    if (vipPackageId.equals(4)) {

                                        VipOrder vipOrder1 = vipOrderService.infoByOrderNo(orderNo);
                                        vipOrder1.setStatus(1);
                                        vipOrderDao.update(vipOrder1);
                                        //生成门票数据
                                        phpUserService.callBackWindowTick(vipOrder1.getUserId());

                                        //回调php


                                        //可以单独传入http参数，这样参数会自动做URL编码，拼接在URL中

                                        Integer types = 1;

                                        String param = "key:26e97719fb48687d42681b0ead73c418,uid:" + vipOrder1.getUserId() + ",money:" + vipOrder1.getPrice() + ",type:" + types;

                                        String ss = Md5Util1.md5Hex(param);

                                        HashMap<String, Object> paramMap = new HashMap<>();

                                        paramMap.put("singer", ss);
                                        paramMap.put("uid", vipOrder1.getUserId());
                                        paramMap.put("money", vipOrder1.getPrice());
                                        paramMap.put("type", types);
                                        String result = HttpUtil.get("https://poposeapi.ptszyxx.com/apa/Shujuhaonv/play", paramMap);

                                        System.out.println(result);


                                    }
                                    //会员  1三天  2一个月  3六个月  7 12个月
                                    if (vipPackageId.equals(1) || vipPackageId.equals(2) || vipPackageId.equals(3) || vipPackageId.equals(7)) {

                                        VipOrder vipOrder1 = vipOrderService.infoByOrderNo(orderNo);
                                        vipOrder1.setStatus(1);
                                        vipOrderDao.update(vipOrder1);
                                        //生成会员数据
                                        phpUserService.callBackVip(vipOrder1.getUserId(), vipPackageId);

                                        Integer types = null;

                                        if (vipPackageId.equals(1)){
                                            types = 2;
                                        }
                                        if (vipPackageId.equals(2)){
                                            types = 3;
                                        }
                                        if (vipPackageId.equals(3)){
                                            types = 4;
                                        }
                                        if (vipPackageId.equals(7)){
                                            types = 5;
                                        }
                                        String param = "key:26e97719fb48687d42681b0ead73c418,uid:" + vipOrder1.getUserId() + ",money:" + vipOrder1.getPrice() + ",type:" + types;

                                        String ss = Md5Util1.md5Hex(param);

                                        HashMap<String, Object> paramMap = new HashMap<>();

                                        paramMap.put("singer", ss);
                                        paramMap.put("uid", vipOrder1.getUserId());
                                        paramMap.put("money", vipOrder1.getPrice());
                                        paramMap.put("type", types);
                                        String result = HttpUtil.get("https://poposeapi.ptszyxx.com/apa/Shujuhaonv/play", paramMap);

                                        System.out.println(result);

                                    }
                                }

                            }
                        }
                    }
                } else {
                    logger.error("通知数据异常！！！");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "success";
    }


//    //回调
//    @RequestMapping(value = "/zfbCallBack", method = RequestMethod.POST)
//    @ResponseBody
//    public String zfbCallBack(HttpServletRequest req, HttpServletResponse resp) throws Exception {
//
//        String data = req.getParameter("data");
//        String sign = req.getParameter("sign");
//        logger.info("接收到前台通知数据：" + data);
//        logger.info("接收到前台通知签名：" + sign);
//        // 验证签名
//        boolean valid;
//        try {
//            valid = CryptoUtil.verifyDigitalSign(data.getBytes("utf-8"), Base64.decodeBase64(sign),
//                    CertUtil.getPublicKey(), "SHA1WithRSA");
//            if (!valid) {
//                logger.error("verify sign fail.");
//                logger.error("签名字符串(data)为：" + data);
//                logger.error("签名值(sign)为：" + sign);
//
//
//            } else {
//                logger.info("verify sign success");
//                JSONObject dataJson = JSONObject.parseObject(data);
//                if (dataJson != null) {
//                    if (dataJson.getJSONObject("head").getString("respCode").equals("000000")) {
//                        String url = "jsp/payResult.jsp";
//                        req.getRequestDispatcher(url).forward(req, resp);
//                        if (dataJson.getJSONObject("body").getString("orderStatus").equals("1")) {
//
//                            String orderNo = dataJson.getJSONObject("body").getString("tradeNo");
//                            if (ObjectUtil.isNotEmpty(orderNo)) {
//
//                                //钱包                                                             4                               1
//                                AppOrder order = appOrderService.getByOrdernum(orderNo, dingdan_zhiFuLeiXing_shande_zfb, dingdan_status_dfk);
//                                if (ObjectUtil.isNotEmpty(order)) {
//
//                                    AppUser user = appUserService.get(order.getUserid());
//                                    //存在则更改预订单支付状态
//                                    appOrderService.updateStastusYzf(order.getOrdernum(), dingdan_zhiFuLeiXing_shande_zfb);
//                                    BigDecimal getDiamond = order.getNum();
//                                    //添加用户钻石金额
//                                    appUserService.updateZuanShi(user.getId(), getDiamond);
//                                    //增加用户累积充值金额
//                                    appUserService.updateLeijiChongzhi(user.getId(), order.getMoney());
//                                    //添加钻石明细
//                                    appMingXiZuanShiService.addMingxi(user.getId(), getDiamond, 1, "钻石充值");
//                                    //添加充值明细
//                                    appMingxiChongzhiService.addMingxi(user.getId(), getDiamond, 1, order.getMoney(), order.getOrdernum(), order.getMobileSpec());
//                                    //完成充值任务
//                                    appDailyTasController.getAwardOnce(order.getUserid(), ClientConstants.TaskOnce.RECHARGE_FIRST);
//                                    //如果有上级发放用户充值提成
//                                    addAward(order);
//                                    //升级贵族
//                                    appPrivilegeService.isUpLevel(user);
//                                }
//
//                                //vip充值
//                                VipOrder vipOrder = vipOrderService.getByOrderNum(orderNo, dingdan_zhiFuLeiXing_shande_zfb, 0);
//                                if (ObjectUtil.isNotEmpty(vipOrder)) {
//
//                                    if (vipOrder.getVipPackageId().equals(1000)) {
//                                        VipOrder vipOrder1 = vipOrderService.infoByOrderNo(orderNo);
//                                        vipOrder1.setStatus(1);
//                                        vipOrderDao.update(vipOrder1);
//                                        //更改状态
//                                        appUserService.upstateWindowTicket(vipOrder.getUserId());
//
//                                    } else {
//                                        //更改订单状态
//                                        vipOrderService.successCall(orderNo);
//                                    }
//
//                                }
//
//                            }
//                        }
//                    }
//                } else {
//                    logger.error("通知数据异常！！！");
//                }
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return "success";
//    }

    /**
     * 邀请用户充值增加父级提成
     *
     * @param order
     */
    public void addAward(AppOrder order) {
        AppInvitationRecord record = appInvitationRecordService.getShangji(order.getUserid());
        if (record != null) {
            AppSetup appSetup = appSetupService.get();
            BigDecimal divide = order.getNum().multiply(appSetup.getRechargeInvite()).setScale(2, BigDecimal.ROUND_HALF_UP);
            appUserService.addDiamonds(record.getPuserid(), divide, "邀请用户充值提成");
        }
    }


}
